package Controller.admin.statistic;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Controller.admin.AdminBaseServlet;
import Entity.Book;

import Services.WebService;
public class StatisticServlet extends AdminBaseServlet {    
    @Override
    protected void processRequest(HttpServletRequest request, HttpServletResponse response, WebService webServices, String action) throws ServletException, IOException {
    	ArrayList<Book> bookList = new ArrayList<Book>();
    	
    	if(action!=null && action.equals("most_purchased")){
    		bookList = webServices.getEntityManager().getMostPurchasedBooks();
    	}
    	else if(action!=null && action.equals("most_viewed")){
    		bookList = webServices.getEntityManager().getMostViewedBooks();
    	}
    	
    	request.setAttribute("action", action);
    	request.setAttribute("bookList", bookList);
    	this.forward(request, response, webServices, action, "/admin/statistics/book.jsp");
    }
}